package com.cyan.note.controller.manager;

import com.cyan.note.common.ApiResult;
import com.cyan.note.dto.manager.dashboard.*;
import com.cyan.note.service.manager.ManagerDashboardService;
import com.cyan.note.util.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 店长端-工作台控制器
 * 
 * @author ZhangzhenYu
 * @since 2025-01-15
 */
@RestController
@RequestMapping("/api/manager/dashboard")
public class ManagerDashboardController {

    @Autowired
    private ManagerDashboardService managerDashboardService;

    /**
     * 获取工作台概览数据
     */
    @GetMapping("/overview")
    public ApiResult<DashboardOverviewDTO> getDashboardOverview() {
        Long shopId = SecurityUtils.getCurrentShopId();
        return managerDashboardService.getDashboardOverview(shopId);
    }

    /**
     * 获取今日核心统计
     */
    @GetMapping("/today-stats")
    public ApiResult<TodayStatsDTO> getTodayStats() {
        Long shopId = SecurityUtils.getCurrentShopId();
        return managerDashboardService.getTodayStats(shopId);
    }

    /**
     * 获取营收趋势数据
     */
    @GetMapping("/revenue-trend")
    public ApiResult<List<RevenueTrendDTO>> getRevenueTrend(
            @RequestParam(defaultValue = "7") Integer days
    ) {
        Long shopId = SecurityUtils.getCurrentShopId();
        return managerDashboardService.getRevenueTrend(shopId, days);
    }

    /**
     * 获取打手状态概览
     */
    @GetMapping("/worker-status")
    public ApiResult<WorkerStatusOverviewDTO> getWorkerStatusOverview() {
        Long shopId = SecurityUtils.getCurrentShopId();
        return managerDashboardService.getWorkerStatusOverview(shopId);
    }

    /**
     * 获取进行中订单监控
     */
    @GetMapping("/active-orders")
    public ApiResult<List<ActiveOrderDTO>> getActiveOrders() {
        Long shopId = SecurityUtils.getCurrentShopId();
        return managerDashboardService.getActiveOrders(shopId);
    }

    /**
     * 获取客户统计概览
     */
    @GetMapping("/customer-stats")
    public ApiResult<CustomerStatsDTO> getCustomerStats() {
        Long shopId = SecurityUtils.getCurrentShopId();
        return managerDashboardService.getCustomerStats(shopId);
    }

    /**
     * 获取服务统计数据
     */
    @GetMapping("/service-stats")
    public ApiResult<List<ServiceStatsDTO>> getServiceStats(
            @RequestParam(defaultValue = "30") Integer days
    ) {
        Long shopId = SecurityUtils.getCurrentShopId();
        return managerDashboardService.getServiceStats(shopId, days);
    }

    /**
     * 获取异常监控数据
     */
    @GetMapping("/alerts")
    public ApiResult<List<AlertDTO>> getAlerts() {
        Long shopId = SecurityUtils.getCurrentShopId();
        return managerDashboardService.getAlerts(shopId);
    }

    /**
     * 获取快速操作数据
     */
    @GetMapping("/quick-actions")
    public ApiResult<QuickActionsDTO> getQuickActions() {
        Long shopId = SecurityUtils.getCurrentShopId();
        return managerDashboardService.getQuickActions(shopId);
    }

    /**
     * 获取最近活动日志
     */
    @GetMapping("/recent-activities")
    public ApiResult<List<RecentActivityDTO>> getRecentActivities(
            @RequestParam(defaultValue = "10") Integer limit
    ) {
        Long shopId = SecurityUtils.getCurrentShopId();
        return managerDashboardService.getRecentActivities(shopId, limit);
    }

    /**
     * 获取月度汇总报告
     */
    @GetMapping("/monthly-report")
    public ApiResult<MonthlyReportDTO> getMonthlyReport(
            @RequestParam(required = false) String month
    ) {
        Long shopId = SecurityUtils.getCurrentShopId();
        return managerDashboardService.getMonthlyReport(shopId, month);
    }

    /**
     * 刷新数据缓存
     */
    @PostMapping("/refresh")
    public ApiResult<Void> refreshDashboard() {
        Long shopId = SecurityUtils.getCurrentShopId();
        return managerDashboardService.refreshDashboard(shopId);
    }
}